package com.xbongbong.paas.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.domain.entity.PaasFormEntity;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.help.ProFormHelp;
import com.xbongbong.pro.enums.errorcodes.ProErrorCodeEnum;
import com.xbongbong.sys.help.ProPermissionHelp;
import com.xbongbong.paas.log.MongoLogHelp;
import com.xbongbong.paas.log.constant.LogMemoConstant;
import com.xbongbong.paas.log.thread.LogThreadPoolBeanConfig;
import com.xbongbong.paas.model.CustomButtonActionModel;
import com.xbongbong.paas.model.LowCodeActionSettingModel;
import com.xbongbong.paas.model.LowCodeServiceInfoModel;
import com.xbongbong.paas.model.PaasFormServiceModel;
import com.xbongbong.paas.service.ServiceRegistrationService;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.CollectionsUtil;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.paas.toolbox.wrap.UserVO;
import com.xbongbong.pro.department.pojo.DepartmentUserPojo;
import com.xbongbong.pro.domain.entity.CustomButtonActionEntity;
import com.xbongbong.pro.domain.entity.LowCodeActionSettingEntity;
import com.xbongbong.pro.domain.entity.LowCodeServiceInfoEntity;
import com.xbongbong.pro.domain.entity.PaasFormServiceEntity;
import com.xbongbong.pro.enums.ErrorCodeEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.enums.permission.enums.ProPermissionAliasEnum;
import com.xbongbong.pro.log.pojo.DetailLogPojo;
import com.xbongbong.pro.serviceregistration.pojo.LowCodeServiceInfoPojo;
import com.xbongbong.pro.serviceregistration.pojo.ParamPojo;
import com.xbongbong.pro.serviceregistration.pojo.dto.ServiceRegistrationAddDTO;
import com.xbongbong.pro.serviceregistration.pojo.dto.ServiceRegistrationDeleteDTO;
import com.xbongbong.pro.serviceregistration.pojo.dto.ServiceRegistrationGetDTO;
import com.xbongbong.pro.serviceregistration.pojo.dto.ServiceRegistrationListDTO;
import com.xbongbong.pro.serviceregistration.pojo.dto.ServiceRegistrationUpdateDTO;
import com.xbongbong.pro.serviceregistration.pojo.vo.ServiceRegistrationAddVO;
import com.xbongbong.pro.serviceregistration.pojo.vo.ServiceRegistrationDeleteVO;
import com.xbongbong.pro.serviceregistration.pojo.vo.ServiceRegistrationGetVO;
import com.xbongbong.pro.serviceregistration.pojo.vo.ServiceRegistrationListVO;
import com.xbongbong.pro.serviceregistration.pojo.vo.ServiceRegistrationUpdateVO;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.domain.entity.WorkOrderFormEntity;
import com.xbongbong.saas.enums.OperateModuleTypeEnum;
import com.xbongbong.saas.enums.OperateTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.service.toolbox.help.LogHelp;
import com.xbongbong.sys.domain.entity.UserEntity;
import com.xbongbong.sys.help.ProPermissionHelp;
import com.xbongbong.sys.model.UserModel;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
 * @author 吴峰
 * @date 2021/03/03 16:46
 */
@Service("serviceRegistrationService")
public class ServiceRegistrationServiceImpl implements ServiceRegistrationService {

    private static final Logger LOG = LoggerFactory.getLogger(ServiceRegistrationServiceImpl.class);

    @Resource
    private LowCodeServiceInfoModel lowCodeServiceInfoModel;
    @Resource
    private UserModel userModel;
    @Resource
    private LogHelp logHelp;
    @Resource
    private MongoLogHelp mongoLogHelp;
    @Resource
    private LogThreadPoolBeanConfig logThreadPoolBeanConfig;
    @Resource
    private PaasFormServiceModel paasFormServiceModel;
    @Resource
    private LowCodeActionSettingModel lowCodeActionSettingModel;
    @Resource
    private CustomButtonActionModel customButtonActionModel;
    @Resource
    private ProFormHelp proFormHelp;

    @Override
    public ServiceRegistrationListVO list(ServiceRegistrationListDTO serviceRegistrationListDTO) throws XbbException {
        ServiceRegistrationListVO serviceRegistrationListVO = new ServiceRegistrationListVO();
        try{
            UserVO userVO = serviceRegistrationListDTO.getLoginUser();
            boolean add = userVO.isAdminOrBoss()
                    || ProPermissionHelp.hasThisPermission(userVO, ProPermissionAliasEnum.SERVICE_REGISTER_ADD.getAlias());
            boolean list = userVO.isAdminOrBoss() || ProPermissionHelp.hasThisPermission(userVO, ProPermissionAliasEnum.SERVICE_REGISTER_VIEW.getAlias());
            if (!list) {
                serviceRegistrationListVO.setAdd(add);
                serviceRegistrationListVO.setLowCodeServiceInfoList(new ArrayList<>());
                return serviceRegistrationListVO;
            }
            String corpid = serviceRegistrationListDTO.getCorpid();
            Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            param.put(StringConstant.CORPID, corpid);
            param.put(StringConstant.DEL, DelEnum.NORMAL.getDel());
            param.put("serviceType", serviceRegistrationListDTO.getServiceType());
            param.put("orderByStr", "update_time desc");
            List<LowCodeServiceInfoEntity> lowCodeServiceInfoList = lowCodeServiceInfoModel.findEntitys(param);
            if (CollectionsUtil.isEmpty(lowCodeServiceInfoList)) {
                serviceRegistrationListVO.setAdd(add);
                serviceRegistrationListVO.setLowCodeServiceInfoList(new ArrayList<>());
                return serviceRegistrationListVO;
            }
            Set<String> userSet = new HashSet<>();
            lowCodeServiceInfoList.forEach(item->{
                if (StringUtil.isNotEmpty(item.getAdministrator())) {
                    userSet.add(item.getAdministrator());
                }
                if (StringUtil.isNotEmpty(item.getUser())) {
                    List<String> userList = JSON.parseArray(item.getUser(), String.class);
                    userSet.addAll(userList);
                }
            });
            Map<String, UserEntity> userMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            if (CollectionsUtil.isNotEmpty(userSet)) {
                List<UserEntity> userList = userModel.findEntitysByUserIds(new ArrayList<>(userSet), corpid);
                userList.forEach(item->{
                    userMap.put(item.getUserId(), item);
                });
            }
            List<LowCodeServiceInfoPojo> resultList = new ArrayList<>();
            lowCodeServiceInfoList.forEach(item->{
                LowCodeServiceInfoPojo lowCodeServiceInfoPojo = setLowCodeServiceInfo(item, userMap, userVO);
                resultList.add(lowCodeServiceInfoPojo);
            });
            serviceRegistrationListVO.setLowCodeServiceInfoList(resultList);

            serviceRegistrationListVO.setAdd(add);
        }  catch (Exception e) {
            LOG.error("serviceRegistrationServiceImpl.list error：", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return serviceRegistrationListVO;
    }

    @Override
    public ServiceRegistrationAddVO add(ServiceRegistrationAddDTO serviceRegistrationAddDTO) throws XbbException {
        ServiceRegistrationAddVO serviceRegistrationAddVO = new ServiceRegistrationAddVO();
        try {
            UserVO userVO = serviceRegistrationAddDTO.getLoginUser();
            ProPermissionHelp.verifyPermission(userVO, ProPermissionAliasEnum.SERVICE_REGISTER_ADD.getAlias());

            String corpid = serviceRegistrationAddDTO.getCorpid();
            Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            param.put(StringConstant.DEL, DelEnum.NORMAL.getDel());
            param.put(StringConstant.CORPID, corpid);
            param.put("serviceType", serviceRegistrationAddDTO.getServiceType());
            List<LowCodeServiceInfoEntity> lowCodeServiceInfoList = lowCodeServiceInfoModel.findEntitys(param);
            if (lowCodeServiceInfoList.size() >= PaasConstant.SERVICE_MAX_SIZE) {
                throw new XbbException(ProErrorCodeEnum.API_ERROR_260032);
            }
            if (CollectionsUtil.isNotEmpty(lowCodeServiceInfoList)) {
                for (LowCodeServiceInfoEntity item : lowCodeServiceInfoList) {
                    if (Objects.equals(item.getName(), serviceRegistrationAddDTO.getName())) {
                        throw new XbbException(ProErrorCodeEnum.API_ERROR_260035);
                    }
                }
            }
            List<String> userList = new ArrayList<>();
            if (CollectionsUtil.isNotEmpty(serviceRegistrationAddDTO.getUser())) {
                serviceRegistrationAddDTO.getUser().forEach(item->{
                    userList.add(item.getId().toString());
                });
            }
            LowCodeServiceInfoEntity lowCodeServiceInfoEntity = new LowCodeServiceInfoEntity(corpid, serviceRegistrationAddDTO.getType(), serviceRegistrationAddDTO.getServiceType(), serviceRegistrationAddDTO.getName(), serviceRegistrationAddDTO.getPlatFormService(),
                    serviceRegistrationAddDTO.getAdmin().get(0).getId().toString(), serviceRegistrationAddDTO.getRequestMethod(), JSON.toJSONString(serviceRegistrationAddDTO.getRequestHeader()), serviceRegistrationAddDTO.getProxyRequest(),
                    JSON.toJSONString(userList), serviceRegistrationAddDTO.getUrl(), serviceRegistrationAddDTO.getSignatureFlag(), serviceRegistrationAddDTO.getSignature(),
                    serviceRegistrationAddDTO.getHmacSecretFlag(), serviceRegistrationAddDTO.getHmacSecret(), JSON.toJSONString(serviceRegistrationAddDTO.getParam()), serviceRegistrationAddDTO.getMemo(), serviceRegistrationAddDTO.getUserId());
            lowCodeServiceInfoEntity.setDel(DelEnum.NORMAL.getDel());
            lowCodeServiceInfoModel.insert(lowCodeServiceInfoEntity);
            serviceRegistrationAddVO.setId(lowCodeServiceInfoEntity.getId());
            // 日志
            String userName= userVO.getName();
            String userId = userVO.getUserId();
            String memo = String.format(I18nMessageUtil.getMessage(LogMemoConstant.LOG_MEMO_USER_ADD_SERVICE_REGISTRATION), userName, serviceRegistrationAddDTO.getName());
            mongoLogHelp.buildLog(corpid, userId, userName, OperateModuleTypeEnum.SERVICE_REGISTRATION, OperateTypeEnum.NEW,
                    lowCodeServiceInfoEntity.getId().toString(), serviceRegistrationAddDTO.getName(), memo, serviceRegistrationAddDTO.getHttpHeader());
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            LOG.error("serviceRegistrationServiceImpl.add error：", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return serviceRegistrationAddVO;
    }

    @Override
    public ServiceRegistrationUpdateVO update(ServiceRegistrationUpdateDTO serviceRegistrationUpdateDTO) throws XbbException {
        ServiceRegistrationUpdateVO serviceRegistrationUpdateVO = new ServiceRegistrationUpdateVO();
        try {
            String corpid = serviceRegistrationUpdateDTO.getCorpid();
            ProPermissionHelp.verifyPermission(serviceRegistrationUpdateDTO.getLoginUser(), ProPermissionAliasEnum.SERVICE_REGISTER_EDIT.getAlias());
            Long id = serviceRegistrationUpdateDTO.getId();


            LowCodeServiceInfoEntity lowCodeServiceInfo = lowCodeServiceInfoModel.getByKey(id, corpid);
            if (Objects.isNull(lowCodeServiceInfo)) {
                throw new XbbException(ProErrorCodeEnum.API_ERROR_260029);
            }
            Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            param.put(StringConstant.DEL, DelEnum.NORMAL.getDel());
            param.put("serviceType", lowCodeServiceInfo.getServiceType());
            param.put("name", serviceRegistrationUpdateDTO.getName());
            param.put(StringConstant.CORPID, corpid);
            List<LowCodeServiceInfoEntity> lowCodeServiceInfoList = lowCodeServiceInfoModel.findEntitys(param);
            if (CollectionsUtil.isNotEmpty(lowCodeServiceInfoList)) {
                for (LowCodeServiceInfoEntity item : lowCodeServiceInfoList) {
                    if (Objects.equals(item.getName(), serviceRegistrationUpdateDTO.getName()) && !Objects.equals(item.getId(), id)) {
                        throw new XbbException(ProErrorCodeEnum.API_ERROR_260035);
                    }
                }
            }
            List<String> userList = new ArrayList<>();
            if (CollectionsUtil.isNotEmpty(serviceRegistrationUpdateDTO.getUser())) {
                serviceRegistrationUpdateDTO.getUser().forEach(item->{
                    userList.add(item.getId().toString());
                });
            }
            LowCodeServiceInfoEntity lowCodeServiceInfoEntity = new LowCodeServiceInfoEntity(serviceRegistrationUpdateDTO.getType(), serviceRegistrationUpdateDTO.getName(), serviceRegistrationUpdateDTO.getPlatFormService(),
                    serviceRegistrationUpdateDTO.getAdmin().get(0).getId().toString(), serviceRegistrationUpdateDTO.getRequestMethod(), JSON.toJSONString(serviceRegistrationUpdateDTO.getRequestHeader()),
                    serviceRegistrationUpdateDTO.getProxyRequest(), JSON.toJSONString(userList), serviceRegistrationUpdateDTO.getUrl(), serviceRegistrationUpdateDTO.getSignatureFlag(),
                    serviceRegistrationUpdateDTO.getSignature(),
                    serviceRegistrationUpdateDTO.getHmacSecretFlag(), serviceRegistrationUpdateDTO.getHmacSecret(), JSON.toJSONString(serviceRegistrationUpdateDTO.getParam()), serviceRegistrationUpdateDTO.getMemo());

            lowCodeServiceInfoEntity.setId(id);
            lowCodeServiceInfoEntity.setCorpid(corpid);
            lowCodeServiceInfoModel.update(lowCodeServiceInfoEntity);
            Runnable runnable = () -> {
                try {
                    JSONObject oldObj = JSONObject.parseObject(JSONObject.toJSONString(lowCodeServiceInfo));
                    JSONObject newObj = JSONObject.parseObject(JSONObject.toJSONString(lowCodeServiceInfoEntity));
                    List<DetailLogPojo> detailArr = logHelp.getDetailArr4Normal(corpid, OperateModuleTypeEnum.SERVICE_REGISTRATION, oldObj, newObj);
                    if (detailArr != null) {
                        String memo = String.format(I18nMessageUtil.getMessage(LogMemoConstant.LOG_MEMO_USER_UPDATE_SERVICE_REGISTRATION), serviceRegistrationUpdateDTO.getLoginUserName(), serviceRegistrationUpdateDTO.getName());
                        // 详情页有更改内容，才记录日志
                        mongoLogHelp.buildLog4DetailArr(detailArr, corpid, serviceRegistrationUpdateDTO.getUserId(), serviceRegistrationUpdateDTO.getLoginUserName(), OperateModuleTypeEnum.SERVICE_REGISTRATION, OperateTypeEnum.EDIT, id.toString(), serviceRegistrationUpdateDTO.getName(), memo, serviceRegistrationUpdateDTO.getHttpHeader());
                    }
                } catch (Exception e) {
                    LOG.error("serviceRegistrationServiceImpl.update error：", e);
                }
            };
            logThreadPoolBeanConfig.sysLogThreadPool().execute(runnable);
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            LOG.error("serviceRegistrationServiceImpl.update error：", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return serviceRegistrationUpdateVO;
    }

    @Override
    public ServiceRegistrationDeleteVO delete(ServiceRegistrationDeleteDTO serviceRegistrationDeleteDTO) throws XbbException {
        ServiceRegistrationDeleteVO serviceRegistrationDeleteVO = new ServiceRegistrationDeleteVO();
        try {
            UserVO userVO = serviceRegistrationDeleteDTO.getLoginUser();
            ProPermissionHelp.verifyPermission(userVO, ProPermissionAliasEnum.SERVICE_REGISTER_DELETE.getAlias());
            String corpid = serviceRegistrationDeleteDTO.getCorpid();

            LowCodeServiceInfoEntity lowCodeServiceInfo = lowCodeServiceInfoModel.getByKey(serviceRegistrationDeleteDTO.getId(), corpid);
            if (Objects.isNull(lowCodeServiceInfo)) {
                throw new XbbException(ProErrorCodeEnum.API_ERROR_260029);
            }
            Integer count = 0;
            Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            param.put(StringConstant.CORPID, corpid);
            param.put(StringConstant.DEL, DelEnum.NORMAL.getDel());
            param.put("serviceId", serviceRegistrationDeleteDTO.getId());
            List<LowCodeActionSettingEntity> lowCodeActionSettingList = lowCodeActionSettingModel.findEntitys(param);

            Set<Long> formIdList = new HashSet<>();
            Set<Long> workOrderFormIdList = new HashSet<>();
            if (CollectionsUtil.isNotEmpty(lowCodeActionSettingList)) {
                lowCodeActionSettingList.forEach(item->{
                   if (Objects.equals(XbbRefTypeEnum.WORK_ORDER.getCode(), item.getBusinessType())) {
                       workOrderFormIdList.add(item.getFormId());
                   } else {
                       formIdList.add(item.getFormId());
                   }
                });
                count =+ lowCodeActionSettingList.size();
            }

            param.clear();
            param.put(StringConstant.CORPID, corpid);
            param.put("serviceId", serviceRegistrationDeleteDTO.getId());
            param.put(StringConstant.DEL, DelEnum.NORMAL.getDel());
            List<CustomButtonActionEntity> buttonList = customButtonActionModel.findEntitys(param);
            if (CollectionsUtil.isNotEmpty(buttonList)) {
                buttonList.forEach(item->{
                    if (Objects.equals(XbbRefTypeEnum.WORK_ORDER.getCode(), item.getBusinessType())) {
                        workOrderFormIdList.add(item.getFormId());
                    } else {
                        formIdList.add(item.getFormId());
                    }
                });
                count =+ buttonList.size();
            }
            param.clear();
            param.put(StringConstant.CORPID, corpid);
            param.put(StringConstant.DEL, DelEnum.NORMAL.getDel());
            param.put("serviceId", serviceRegistrationDeleteDTO.getId());
            List<PaasFormServiceEntity> formServiceList = paasFormServiceModel.findEntitys(param);
            if (CollectionsUtil.isNotEmpty(formServiceList)) {
                formServiceList.forEach(item->{
                    if (Objects.equals(XbbRefTypeEnum.WORK_ORDER.getCode(), item.getBusinessType())) {
                        workOrderFormIdList.add(item.getFormId());
                    } else {
                        formIdList.add(item.getFormId());
                    }
                });
                count =+ formServiceList.size();
            }
            Map<Long, PaasFormEntity> formList = proFormHelp.getFormMap(formIdList, corpid, DelEnum.NORMAL.getDel());
            Map<Long, WorkOrderFormEntity> workOrderFormList = proFormHelp.getWorkOrderFormMap(formIdList, corpid, DelEnum.NORMAL.getDel());
            List<String> formNameList = new ArrayList<>();
            formList.forEach((key, value)->{
                formNameList.add(value.getName());
            });
            workOrderFormList.forEach((key,value)->{
                formNameList.add(value.getName());
            });
            if (count > 0) {
                // 正在使用中的服务注册不允许删除
                throw new XbbException(ProErrorCodeEnum.API_ERROR_260031, String.format(ProErrorCodeEnum.API_ERROR_260031.getMsg(), lowCodeServiceInfo.getName(), StringUtils.join(formNameList, "、")));
            }
            lowCodeServiceInfoModel.deleteByKey(serviceRegistrationDeleteDTO.getId(), corpid);
            // 日志
            String userName= userVO.getName();
            String userId = userVO.getUserId();
            String memo = String.format(I18nMessageUtil.getMessage(LogMemoConstant.LOG_MEMO_USER_DELETE_SERVICE_REGISTRATION), userName, lowCodeServiceInfo.getName());
            mongoLogHelp.buildLog(corpid, userId, userName, OperateModuleTypeEnum.SERVICE_REGISTRATION, OperateTypeEnum.DELETE,
                    serviceRegistrationDeleteDTO.getId().toString(), lowCodeServiceInfo.getName(), memo, serviceRegistrationDeleteDTO.getHttpHeader());
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            LOG.error("serviceRegistrationServiceImpl.update error：", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return serviceRegistrationDeleteVO;
    }

    @Override
    public ServiceRegistrationGetVO get(ServiceRegistrationGetDTO serviceRegistrationGetDTO) throws XbbException {
        try{
            ServiceRegistrationGetVO serviceRegistrationListVO = new ServiceRegistrationGetVO();
            String corpid = serviceRegistrationGetDTO.getCorpid();
            Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            param.put(StringConstant.CORPID, corpid);
            param.put(StringConstant.DEL, DelEnum.NORMAL.getDel());
            LowCodeServiceInfoEntity lowCodeServiceInfoEntity = lowCodeServiceInfoModel.getByKey(serviceRegistrationGetDTO.getServiceRegistrationId(), corpid);
            if (Objects.isNull(lowCodeServiceInfoEntity)) {
                return serviceRegistrationListVO;
            }
            Set<String> userSet = new HashSet<>();
            if (StringUtil.isNotEmpty(lowCodeServiceInfoEntity.getAdministrator())) {
                userSet.add(lowCodeServiceInfoEntity.getAdministrator());
            }
            if (StringUtil.isNotEmpty(lowCodeServiceInfoEntity.getUser())) {
                List<String> userList = JSON.parseArray(lowCodeServiceInfoEntity.getUser(), String.class);
                userSet.addAll(userList);
            }
            List<UserEntity> userList = userModel.findEntitysByUserIds(new ArrayList<>(userSet), corpid);
            Map<String, UserEntity> userMap = new HashMap<>(userList.size());
            userList.forEach(item->{
                userMap.put(item.getUserId(), item);
            });
            LowCodeServiceInfoPojo lowCodeServiceInfoPojo = setLowCodeServiceInfo(lowCodeServiceInfoEntity, userMap, serviceRegistrationGetDTO.getLoginUser());
            serviceRegistrationListVO.setLowCodeServiceInfo(lowCodeServiceInfoPojo);
            return serviceRegistrationListVO;
        }  catch (Exception e) {
            LOG.error("serviceRegistrationServiceImpl.list error：", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
    }

    /**
     * 设置低代码服务注册信息
     * @param lowCodeServiceInfoEntity
     * @param userMap
     * @return com.xbongbong.pro.serviceregistration.pojo.LowCodeServiceInfoPojo
     * @author 吴峰
     * @date 2021/3/5 14:12
     * @throws XbbException
     */
    private LowCodeServiceInfoPojo setLowCodeServiceInfo(LowCodeServiceInfoEntity lowCodeServiceInfoEntity, Map<String, UserEntity> userMap, UserVO userVO) {
        LowCodeServiceInfoPojo lowCodeServiceInfoPojo = new LowCodeServiceInfoPojo(lowCodeServiceInfoEntity.getId(), lowCodeServiceInfoEntity.getCorpid(), lowCodeServiceInfoEntity.getType(), lowCodeServiceInfoEntity.getServiceType(),
                lowCodeServiceInfoEntity.getName(), lowCodeServiceInfoEntity.getPlatFormService(), lowCodeServiceInfoEntity.getUrl(),
                lowCodeServiceInfoEntity.getSignatureFlag(), lowCodeServiceInfoEntity.getSignature(), lowCodeServiceInfoEntity.getHmacSecretFlag(),
                lowCodeServiceInfoEntity.getHmacSecret(), lowCodeServiceInfoEntity.getRequestMethod(), JSON.parseObject(lowCodeServiceInfoEntity.getRequestHeader()), lowCodeServiceInfoEntity.getProxyRequest(),
                JSON.parseArray(lowCodeServiceInfoEntity.getParam(), ParamPojo.class), lowCodeServiceInfoEntity.getMemo());
        if (StringUtil.isNotEmpty(lowCodeServiceInfoEntity.getAdministrator())) {
            UserEntity userEntity = userMap.get(lowCodeServiceInfoEntity.getAdministrator());
            DepartmentUserPojo departmentUserPojo = new DepartmentUserPojo();
            departmentUserPojo.setId(userEntity.getUserId());
            departmentUserPojo.setName(userEntity.getName());
            List<DepartmentUserPojo> list = new ArrayList<>();
            list.add(departmentUserPojo);
            lowCodeServiceInfoPojo.setAdmin(list);
        }
        if (StringUtil.isNotEmpty(lowCodeServiceInfoEntity.getUser())) {
            List<String> user = JSON.parseArray(lowCodeServiceInfoEntity.getUser(), String.class);
            List<DepartmentUserPojo> userPojos = new ArrayList<>();
            user.forEach(item->{
                UserEntity userEntity = userMap.get(item);
                DepartmentUserPojo departmentUserPojo = new DepartmentUserPojo();
                departmentUserPojo.setId(userEntity.getUserId());
                departmentUserPojo.setName(userEntity.getName());
                userPojos.add(departmentUserPojo);
            });
            lowCodeServiceInfoPojo.setUser(userPojos);
            boolean update = userVO.isAdminOrBoss()
                    || ProPermissionHelp.hasThisPermission(userVO, ProPermissionAliasEnum.SERVICE_REGISTER_EDIT.getAlias());
            lowCodeServiceInfoPojo.setUpdate(update);
            boolean delete = userVO.isAdminOrBoss()
                    || ProPermissionHelp.hasThisPermission(userVO, ProPermissionAliasEnum.SERVICE_REGISTER_DELETE.getAlias());
            lowCodeServiceInfoPojo.setDelete(delete);
        }
        return lowCodeServiceInfoPojo;
    }
}
